import request from "@/utils/request";
import { RequestMethodsEnum, ContentTypeEnum } from "@/enums/requestEnums";
const prefix = "/system/tool/";

/**
 * 获取数据源列表
 * @param params
 * @returns
 */
export function datasourceList(params: any) {
  return request.get({ url: prefix + "gen/datasource/list", params });
}
/**
 * 获取数据员响应
 * @param params
 * @returns
 */
export function getDatasourceInfo(params: any) {
  return request.get({ url: prefix + "gen/datasource/" + params });
}

/**
 * 新增 数据源
 * @param params
 * @returns
 */
export function addDataSource(params: any) {
  return request.post(
    {
      url: prefix + "gen/datasource",
      params,
    },
    { isParamsToData: false } //设置为false 标识发送表单请求
  );
}

/**
 * 修改数据源
 * @param params
 * @returns
 */
export function editDataSource(params: any) {
  return request.post({ url: prefix + "gen/datasource/edit", params });
}
/**
 * 删除数据源
 * @param params
 * @returns
 */
export function delDataSource(params: any) {
  return request.post({ url: prefix + "gen/datasource/del", params });
}

// 代码生成已选数据表列表接口
export function generateTable(params: any) {
  return request.get({ url: prefix + "gen/list", params });
}

/**
 * 查询指定数据源的表
 * @param params
 * @returns
 */
export function dataTable(params: any) {
  return request.post({ url: prefix + "gen/db/list", params }, {});
}

// 数据表所有列表接口
export function dataTableAll() {
  return request.get({ url: "/gen/dbAll" });
}

//表名查字段
export function dataTableToColumn(params: any) {
  return request.get({ url: "/gen/dbColumn", params });
}
/**
 * 选择要生成代码的数据表
 * 已经同步表结构了
 * @param params  {storeId:"",tables:"xx,xxx"}
 * @returns
 */
export function selectTable(params: any) {
  return request.post(
    { url: prefix + "gen/importTable", params },
    {
      isParamsToData: false,
    }
  );
}

// 已选择的数据表详情
export function tableDetail(params: any) {
  return request.get({ url: prefix + "gen/" + params.id });
}

/**
 * 删除已选择的数据表
 * @param params  [id]
 * @returns
 */
export function generateDelete(params: any) {
  return request.post({ url: prefix + "gen/delGenCode", params });
}

//编辑已选表字段
export function generateEdit(params: any) {
  return request.post({ url: prefix + "gen/edit", params });
}

/**
 * 预览代码
 * @param params  tableId
 * @returns
 */
export function generatePreview(params: any) {
  return request.get({ url: prefix + "gen/preview/" + params });
}

//生成代码
export function generateCode(params: any) {
  return request.get({ url: prefix + "gen/genCode/" + params, params });
}

/**
 * 下载代码
 * @param params tableName
 * @returns
 */
export function downloadCode(params: any) {
  return request.get(
    { responseType: "blob", url: prefix + "gen/download/" + params, params },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * 下载代码 批量
 * @param params  '表1,表2'
 * @returns
 */
export function batchGenCode(params: any) {
  return request.get(
    {
      responseType: "blob",
      url: prefix + "gen/batchGenCode/" + params,
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
